<?php
require("init.php");

if (isset($_REQUEST['u']) && isset($_REQUEST['address'])) {
	$client = new client();
	$url = $_REQUEST['u'];
	$address = $_REQUEST['address'];	
	$addressId = isset($_REQUEST['addressId'])?$_REQUEST['addressId']:NULL;
	$type = $_REQUEST['type'];
	$templateId = isset($_REQUEST['templateId'])?$_REQUEST['templateId']:0;
	$url = base64_decode($url);
	
    $urlA = explode(".", $url);
    $urlA[0] = $clickJumpUrl;   //define jump url not with .COM
	$urls = '';
    foreach ($urlA as $key => $value) {
        $urls = $urls.$value.".";
    }
    $urls = trim($urls, ".");
    
	$url = addslashes($urls);
	$addressId = addslashes($addressId);
	$address = addslashes($address);
	$ip = $client->get_user_ip();

	$brownserLanguage = $client->get_user_lang();
	$flag = ipLimit($ip,"segment",$ipSegmentArr);

	if(preg_match('/^[\S]*$/',$brownserLanguage)||empty($brownserLanguage)||$flag==TRUE){
		$sql = "select * from jumpUrl where id = ".$templateId."";
		$arr = $GLOBALS['db']->dbGetRow($sql);
		$urlF = $arr['url'];
	}
	$sql = "insert into clickTrack(url, addressId, address, ip, type, timeStamps, templateId, brownserLanguage, urlF) values('".$urls."', '".$addressId."', '".$address."', '".$ip."', '".$type."', ".time().", ".$templateId.", '".$brownserLanguage."', '".$urlF."')";
//		echo $sql;
	$GLOBALS['db']->dbquery($sql);
	$address = urlencode($address);
	//sleep(1);
	$brownserLanguage = trim($brownserLanguage);
	if($flag===FALSE){
		if(preg_match('/^[\S]*$/',$brownserLanguage)||!empty($brownserLanguage)){
			if(preg_match('/com\/$/',$urls)){
				$url = $urls;
			}else{
				$url = $urls."?id=".$address;
			}
		}
	}else{
		$url = $arr['url'];
	}
//	print_r($url);exit;
	header('Location:'.$url);	
}else{
	exit("don't try");
}


?>